package com.bydq.patrolsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bydq.patrolsystem.entity.PsInspectiontaskDetail;
import com.bydq.patrolsystem.mapper.PsInspectiontaskDetailMapper;
import com.bydq.patrolsystem.service.PsInspectiontaskDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 写代码是不可能写代码的啦~~
 * @since 2020-05-22
 */
@Service
public class PsInspectiontaskDetailServiceImpl extends ServiceImpl<PsInspectiontaskDetailMapper, PsInspectiontaskDetail> implements PsInspectiontaskDetailService {
    @Autowired
    PsInspectiontaskDetailMapper psInspectiontaskDetailMapper;

    //查询缺陷确认列表
    @Override
    public IPage<PsInspectiontaskDetail> selectInspectionTaskListByPaging(String inspectionTaskCode,List<Long> taskIds, String lineCode,
                                                                          String poleCode, String discovererName,
                                                                          Long bugType, Long bugLevel, String startDate,
                                                                          String endDate, Integer page, Integer limit) {
        page = page == null ? 1 : page;
        limit = limit == null ? 3 : limit;
        QueryWrapper<PsInspectiontaskDetail> qw=new QueryWrapper<>();
        if(taskIds!=null){
            for(Long taskId:taskIds){
                qw.eq("taskId",taskId);
            }
        }
//        System.out.println("taskIds"+taskIds);
        if(inspectionTaskCode!=null&&inspectionTaskCode!=""&&taskIds.size()<1){
            qw.eq("taskId",-1);
        }

        qw.like(lineCode!=null&&lineCode!="","lineCode",lineCode);
        qw.like(poleCode!=null&&poleCode!="","poleCode",poleCode);
        qw.like(discovererName!=null&&discovererName!="","discovererName",discovererName);
        qw.eq(bugType!=null,"bugType",bugType);
        qw.eq(bugLevel!=null,"bugLevel",bugLevel);
        qw.between(startDate!=null&&endDate!=null&&startDate!=""&&endDate!="","discoverTime",startDate,endDate);
        qw.eq("isBug",1).eq("isSolve",0).eq("isBugLevel",0).eq("taskStatus",4);
        return psInspectiontaskDetailMapper.selectInspectionTaskListByPaging(new Page<>(page, limit), qw);
    }
}